﻿using AutoMapper;
using ERP.Domain.Order_Module;
using ERP.ErrorCode;
using ERP.Infratructure.Interface;
using ERP.Server.API.Applocation.Command;
using MediatR;

namespace ERP.Server.API.Applocation.Handler
{
    /// <summary>
    /// 仓库管理查询命令处理
    /// </summary>
    public class OrderCreateCommandHandler : IRequestHandler<OrderCreateCommand, APIResult<int>>
    {
        IBaseRepository<OrderModel> orderRep;
        IMapper mapper;
        public OrderCreateCommandHandler(IBaseRepository<OrderModel> orderRep,IMapper mapper)
        {
            this.orderRep = orderRep;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(OrderCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code=ResultCode.添加成功;
            result.Message=ResultCode.添加成功.ToString();
            OrderModel order= mapper.Map<OrderModel>(request);  
            await orderRep.AddAsync(order);
            return await Task.FromResult(result);
        }

    }
}
